<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="主表id" prop="primaryId">
        <el-input
          v-model="queryParams.params.primaryId"
          placeholder="请输入主表id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品id" prop="productId">
        <el-input
          v-model="queryParams.params.productId"
          placeholder="请输入产品id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品型号" prop="model">
        <el-input
          v-model="queryParams.params.model"
          placeholder="请输入产品型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数量" prop="number">
        <el-input
          v-model="queryParams.params.number"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单价" prop="price">
        <el-input
          v-model="queryParams.params.price"
          placeholder="请输入单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="税率" prop="tax">
        <el-input
          v-model="queryParams.params.tax"
          placeholder="请输入税率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="税额" prop="taxMoney">
        <el-input
          v-model="queryParams.params.taxMoney"
          placeholder="请输入税额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="金额" prop="money">
        <el-input
          v-model="queryParams.params.money"
          placeholder="请输入金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleFilter">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetSearch">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleCreate"
          v-hasPermi="['business:practices:save']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:practices:save']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDeletes"
          v-hasPermi="['business:practices:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="exportExcel"
          v-hasPermi="['business:practices:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="handleFilter"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="list"
      :height="tableHeight"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="主表id" align="center" prop="primaryId" />
      <el-table-column label="产品id" align="center" prop="productId" />
      <el-table-column label="产品型号" align="center" prop="model" />
      <el-table-column label="数量" align="center" prop="number" />
      <el-table-column label="单价" align="center" prop="price" />
      <el-table-column label="税率" align="center" prop="tax" />
      <el-table-column label="税额" align="center" prop="taxMoney" />
      <el-table-column label="金额" align="center" prop="money" />
      <el-table-column label="部门状态" align="center" prop="status" />
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        min-width="140"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:practices:save']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:practices:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="fetchData"
    />

    <!--编辑-->
    <Edit
      :visible.sync="dialogFormVisible"
      :dialogStatus="dialogStatus"
      :form="form"
      @success="saveSuccess"
    ></Edit>
  </div>
</template>

<script>
import { practices } from "@/api/business/practices";
import Edit from "./components/edit";
import { listMixin } from "@/mixins/list"

export default {
  name: "Practices",
  mixins: [ listMixin ],
  components: { Edit },
  data() {
    return {

    };
  },
  created() {
    //获取列表数据
    this.fetchData();
  },
  methods: {
    //调用list接口
    callList(queryParams) {
      return new Promise(function(resolve, reject) {
        practices.list(queryParams).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error)
        });
      });
    },
    //调用findById接口
    callFindById(id) {
      return new Promise(function(resolve, reject) {
        practices.findById(id).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error)
        });
      });
    },
    //调用delete接口
    callDelete(id) {
      return new Promise(function(resolve, reject) {
        practices.del(id).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error)
        });
      });
    },
    //调用batchDel接口
    callDeletes(ids) {
      return new Promise(function(resolve, reject) {
        practices.batchDel(ids).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error)
        });
      });
    },
    //调用exportExcel接口
    callExport(queryParams) {
      let _this = this;
      return new Promise(function(resolve, reject) {
        _this.download('business/practices/export', {
          ...queryParams
        }, `练习子_`+new Date().getTime()+`.xlsx`)
      });
    }
  }
};
</script>

<style lang="scss" scoped>

</style>
